import pygame
from settings import *
from cell import Cell
from player import Player

class World:
    def __init__(self):
        # Получение экрана
        self.display_surface = pygame.display.get_surface()

        # Создание групп срайтов
        self.visible_sprites = pygame.sprite.Group()
        self.barier_sprites = pygame.sprite.Group()
        self.create_map()

    def create_map(self):
        for r_index, row in enumerate(MAP):
            for c_index, col in enumerate(row):
                x = CELLSIZE * c_index
                y = CELLSIZE * r_index
                if col == 'x':
                    Cell((x, y), [self.visible_sprites, self.barier_sprites])
                if col == 'p':
                    self.player = Player((x, y), [self.visible_sprites], self.barier_sprites)

    def update_world(self):
        self.visible_sprites.draw(self.display_surface)
        self.visible_sprites.update()
